package com.android.readcard.dialog;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
import android.widget.TextView;

import com.android.readcard.R;


/**
 * Created by UyPlayer on 2017/2/17.
 */

public class YqDialog extends Dialog {

    private Context context;
    private TextView dialog_name;
    private TextView titleCard;
    private TextView dialog_cancle;
    private String mStr;
    private String mTitle;

    public YqDialog(Context context) {
        super(context, R.style.QiaoDaoDialogStyle);
        this.context = context;
    }

    public void setStr(String str) {
        this.mStr = str;
    }

    public void setTitle(String str) {
        this.mTitle = str;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.yq_dialog);
        dialog_name = (TextView) findViewById(R.id.dialog_name);
        titleCard = (TextView) findViewById(R.id.titleCard);
        dialog_cancle = (TextView) findViewById(R.id.dialog_cancle);
        dialog_name.setText(mStr);
        titleCard.setText(mTitle);
        dialog_cancle.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        if (event.getAction() == MotionEvent.ACTION_MOVE) {
            dismiss();
            return true;
        }
        return super.onTouchEvent(event);
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
            dismiss();
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }

}
